/**
 * Generate code from /{{projectName}}-user/src/main/java/{{packageName}}/{{apis}}/rest/{{apiEntities}}ResourceImpl.java.hbs
 */
// @SkipOverwrite
package cn.ibizlab.api.rest;

import cn.ibizlab.api.dto.SysDeploySystemDTO;
import cn.ibizlab.core.system.domain.SysDeploySystem;
import cn.ibizlab.util.helper.JacksonUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 实体[SysDeploySystem] rest实现
 *
 * @author generator
 */
@Slf4j
public class SysDeploySystemResourceImpl extends AbstractSysDeploySystemResource {

    @PostMapping("sys_deploy_systems/deployresource/{system}")
    public ResponseEntity<String> deployResource(@PathVariable("system") String system, @RequestBody byte[] resource) {
        String info = "";
        try {
            SysDeploySystem deploySystem = JacksonUtils.mapper.readValue(resource, SysDeploySystem.class).setSystemId(system).setId(system);
            sysDeploySystemService.save(deploySystem);
            info = "向uaa部署系统完成. "+deploySystem.getOrDefault("deploy_info","");
        }
        catch (Exception ex) {
            info = "向uaa部署系统失败. "+ex.getMessage();
        }
        return ResponseEntity.ok(info);
    }

    @ApiOperation(value = "GetPermissions", tags = {"系统" },  notes = "SysDeploySystem-GetPermissions ")
    @PostMapping("sys_deploy_systems/{id}/getpermissions")
    public ResponseEntity<SysDeploySystemDTO> getPermissions(@PathVariable("id") String id) {
        return super.getPermissionsById(id);
    }
}
